package com.zsc.newbuds.controller.admin;

import com.zsc.newbuds.entity.Admin;
import com.zsc.newbuds.service.impl.AdminServiceImpl;
import com.zsc.newbuds.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 后台管理控制器
 * @author D
 */
@RequestMapping("admin/empManagement")
@Controller
public class EmpManageController {

    @Autowired
    UserServiceImpl userService;

    @Autowired
    AdminServiceImpl adminService;
    /**
     * 判断admin账号是否已经存在
     * @param account
     * @return
     */
    @ResponseBody
    @GetMapping("/judgeAccount")
    public int judgeAccount(String account){
        System.out.println(account);
        return adminService.judgeAccount(account);
    }

    /**
     * 增加工作人员
     * @param account
     * @param name
     * @param phone
     * @param password
     * @return
     */
    @ResponseBody
    @GetMapping("/addAdmin")
    public int addAdmin(String account,String name,String phone,String password,String area){
        System.out.println(account+" "+name+" "+phone+""+password);
        Admin admin = new Admin();
        admin.setAccount(account);
        admin.setAdminName(name);
        admin.setPhone(phone);
        admin.setPassword(password);
        admin.setPosition("work");
        admin.setOderNumber(0);
        admin.setAddress(area);
        admin.setAdminImage("http://dd.ddandang.top/headportrait/test.jpeg");
        admin.setWorkArea("未分配");
        adminService.addAdmin(admin);
        System.out.println(admin);
        return 1;
    }

    /**
     * 返回工作人员集合
     */
    @ResponseBody
    @GetMapping("/getWorkList")
    public List<Admin> getWorkList(){
        List<Admin> adminList = adminService.getWorkList("work");
        System.out.println(adminList);
        return adminList;
    }

    @ResponseBody
    @GetMapping("/getVolunteerList")
    public List<Admin> getVolunteerList(){
        List<Admin> adminList = adminService.getVolunteerList("volunteer");
        System.out.println(adminList);
        return adminList;
    }


    @ResponseBody
    @GetMapping("/deleteWork")
    public void deleteWork(Integer adminId){
        System.out.println(adminId);
        adminService.deleteAdmin(adminId);

    }

    @ResponseBody
    @PostMapping("/deleteVolunteer")
    public void deleteVolunteer(Integer volunteerId){
        System.out.println(volunteerId);
        //从员工中删除志愿者
        adminService.deleteVolunteer(volunteerId);
        //从用户中删除志愿者
        userService.deleteVolunteer(volunteerId);
    }
}
